package microcredit.gui.util;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;

public class FormatUtilities {

	public static String formatMoney(BigDecimal decimal) {
		if (decimal == null) {
			return "";
		}
		return getMoneyFormat().format(decimal);
	}
	public static NumberFormat getMoneyFormat() {
		NumberFormat format = NumberFormat.getInstance(Locale.ENGLISH);
		format.setMinimumFractionDigits(2);
		return format;
	}
	
	public static String formatLongDate(Date date) {
		//TODO implement a better format for long
		return formatDate(date);
	}
	
	public static String formatDate(Date date) {
		if (date == null) {
			return "";
		}
		return getDateFormat().format(date);
	}
	
	public static String formatDateTime(Date date) {
		if (date == null) {
			return "";
		}
		return getDateTimeFormat().format(date);
	}
	
	public static DateFormat getDateTimeFormat() {
		return DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT);
	}
	
	public static DateFormat getDateFormat() {
		return DateFormat.getDateInstance(DateFormat.DEFAULT);
	}
	
}
